<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{_fragments::common_header(~{::title})}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../static/css/bootstrap.min.css"
	th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet">
<script src="../../static/js/jquery-3.2.1.js"
	th:src="@{/static/js/jquery-3.2.1.js}"></script>
<script src="../../static/js/bootstrap.min.js"
	th:src="@{/static/js/bootstrap.min.js}"></script>
<title>逍遥论坛 ›修改贴子信息</title>
</head>
<body>
	<!-- 引入header文件 -->
	<header th:replace=" _fragments:: header"></header>

	<div style="width: 70%; margin: 1% 2% 1% 5%; float: left;">
		<div class="panel panel-default" id="main" style="">
			<div class="panel-heading" style="background-color: white">
				<a href="<%=basePath%>">逍遥论坛</a> › 修改贴子信息 › <a
					th:href="'showTip.do?tipId='+${tip.tipId}" th:text="${tip.tipTitle}"></a>
			</div>

			<div class="panel-body">
				<form th:action="'updeteModifyTipPage.do?myTip='+${myTip}" id="myTipUpdateForm" method="POST"
					class="form-horizontal" role="form">
					<table class="table">
						<thead>
							<tr>
								<th>名称</th>
								<th>修改前</th>
								<th>修改后</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>ID</td>
								<td th:text="${tip.tipId}"></td>
								<td><input class="form-control" type="hidden" name="tipId"
									th:value="${tip.tipId}" /></td>
							</tr>
							<tr>
								<td>版块</td>
								<td th:text="${tip.forumName}">${tip.tab.forum.forum_name}</td>
								<td><select class="form-control" id="selectForum"
									name="forumId" onchange="selectForumFunc()">
										<!--<c:forEach items="${forums}" var="forum">
                                        <c:choose>
                                            <c:when test="${tip.tab.forum.forum_id} == ${forum.forum_id}">
                                                <option value="${forum.forum_id}" selected>${forum.forum_name}</option>
                                            </c:when>
                                            <c:otherwise>
                                                <option value="${forum.forum_id}">${forum.forum_name}</option>
                                            </c:otherwise>
                                        </c:choose>
                                    </c:forEach>-->
										<div th:each="forum,iterStat:${forum}">
												<option th:if="${tip.forumId==forum.forumId}" th:value="${forum.forumId}"
													th:text="${forum.forumName}" selected>${forum.forum_name}</option>
												<option  th:if="${tip.forumId!=forum.forumId}" th:value="${forum.forumId}"
													th:text="${forum.forumName}"></option>
													</div>
								</select></td>
							</tr>
							<tr>
								<td>分类</td>
								<td th:text="${tip.tabName}"></td>
								<td><select class="form-control" id="selectTab"
									name="tabId">
										<!--            <c:forEach items="${tabs}" var="tab">
                                        <c:choose>
                                            <c:when test="${tip.tab.tab_id} == ${tab.tab_id}">
                                                <option value="${tab.tab_id}" selected>${tab.tab_name}</option>
                                            </c:when>
                                            <c:otherwise>
                                                <option value="${tab.tab_id}">${tab.tab_name}</option>
                                            </c:otherwise>
                                        </c:choose>
                                    </c:forEach> -->
										<div th:each="tab,iterStat:${tab}">

											<option th:if="${tip.tabId==tab.tabId}"
												th:value="${tab.tabId}" th:text="${tab.tabName}" selected>${tab.tab_name}</option>

											<option th:if="${tip.tabId!=tab.tabId}"
												th:value="${tab.tabId}" th:text="${tab.tabName}"></option>

										</div>
								</select></td>
							</tr>
							<tr>
								<td>楼主</td>
								<td th:text="${tip.userName}"><!-- <c:choose>
										<c:when test="${not empty tip.user.user_nick}">${tip.user.user_nick}</c:when>
										<c:otherwise>${tip.user.user_name}</c:otherwise>
									</c:choose> --></td>
								<td></td>
							</tr>
							<tr>
								<td>标题</td>
								<td th:text="${tip.tipTitle}">${tip.tip_title}</td>
								<td><input class="form-control" type="text"
									name="tipTitle" th:value="${tip.tipTitle}" required /></td>
							</tr>
							<tr>
								<td>内容</td>
								<td th:text="${tip.tipContent}">${tip.tip_content}</td>
								<td><textarea class="form-control" rows="2"
										name="tipContent" th:text="${tip.tipContent}" required>${tip.tip_content}</textarea></td>
							</tr>
							<tr>
								<td>回复数</td>
								<td th:text="${tip.tipReplies}">${tip.tip_replies}</td>
							</tr>
							<tr>
								<td>发表时间:<span th:text="${#dates.format(tip.tipPublishtime,'yyyy-MM-dd')}"></span><br>更新时间:<span th:text="${#dates.format(tip.tipModifytime,'yyyy-MM-dd')}"></span>
								</td>
								<td><fmt:formatDate value="${tip.tip_publishTime}"
										pattern="yyyy-MM-dd HH:mm:ss" /> <br> <fmt:formatDate
										value="${tip.tip_modifyTime}" pattern="yyyy-MM-dd HH:mm:ss" />
								</td>
							</tr>
							<tr>
								<td>点击量</td>
								<td th:text="${tip.tipClick}">${tip.tip_click}</td>
							</tr>
							<tr>
								<td>状态</td>
								<td>
                                    <div th:switch="${tip.tipIsdeleted}">
                                        <span th:case="1">删除</span>
                                        <span th:case="*">正常</span>
                                    </div>
                                    <div th:switch="${tip.tipIsknot}">
                                        <span th:case="1">结贴</span>
                                        <span th:case="*">未结贴</span>
                                    </div>
                                   <!-- <c:choose>
										<c:when test="${tip.tip_isDeleted == 1}">删除</c:when>
										<c:otherwise>正常</c:otherwise>
									</c:choose> <br> <c:choose>
										<c:when test="${tip.tip_isKnot == 1}">结贴</c:when>
										<c:otherwise>未结贴</c:otherwise>
									</c:choose>--></td>
							</tr>
							<tr>
								<td>操作</td>
								<td><input class="btn btn-warning" type="button" value="修改"
									onclick="update_confirm()" /> <input class="btn btn-default"
									type="reset" value="重填" /> <input type="button"
									class="btn btn-default" value="返回" style="margin-left: 10%"
									onclick="window.location.href='<%=basePath%>toTipManagePage.do'" />
								</td>
							</tr>
						</tbody>
					</table>
				</form>
			</div>
		</div>
	</div>

	<!-- 引入侧边栏文件 -->
	<!-- <%@ include file="side.jsp"%> -->
	<nav th:replace="side:: nav"></nav>

	<!-- 引入footer文件 -->
	<!-- <%@ include file="footer.jsp"%> -->
	<footer th:replace="_fragments:: footer"></footer>

	<script>
		function update_confirm() {
			var r = confirm("确定修改?")
			if (r == true) {
				var form = document.getElementById("myTipUpdateForm"); // 由id获取表单
				form.submit();
			} else {
			}
		}

		function selectForumFunc() {
			// 获取选择的项目 jquery
			var selectedForum = $('select option:selected').val();
			// 获取分类下拉栏id
			var selectTab = document.getElementById("selectTab");
			// alert("您选择了：" + selectedForum);
			if (selectedForum != null) {
				$
						.ajax({
							url : "<%=basePath%>getTabBySelectedForum.do",
							type : "post",
							data : {
								selectedForum : selectedForum
							},
							dataType : "json",
							success : function(data) {
								var tabList = data;
								if (tabList) {
									// 清除选项
									selectTab.options.length = 0;
									var optionStr = "";
									// 先加一个无用的选项
									optionStr += "<option value=\"\" selected>请选择分类</option>";
									for (var i = 0; i < tabList.length; i++) {
										optionStr += "<option value=\"" + tabList[i].tab_id + "\">"
												+ tabList[i].tab_name
												+ "</option>";
									}
									//alert("将要添加的optionStr = " + optionStr);
									// 添加到select标签（刷新选项）
									$("select[id=selectTab]").append(optionStr);
								}
							}
						})
			} else {
				alert("selectedForum == null");
				selectTab.options.length = 0;
			}
		}
	</script>

</body>
</html>